package xyz.suancaiyu.userservice.config;

import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * @author puruidong
 * @version 2019/1/25 0:31
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {


    private List<Parameter> parameter() {
        return List.of(new ParameterBuilder().name("Authorization")
                .description("Authorization Bearer token")
                .modelRef(new ModelRef("string"))
                .parameterType("header")
                .required(false).build());
    }

    @Bean
    public Docket sysApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("xyz.suancaiyu.userservice.web"))
                .paths(PathSelectors.any())
                .build().globalOperationParameters(parameter());
        //.securitySchemes(newArrayList(oauth()))
        // .securityContexts(newArrayList(securityContext()));
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("suancaiyu", "", "pruidong@gmail.com");
        return new ApiInfoBuilder()
                .title("user-service api")
                .description("user-service 微服务")
                .termsOfServiceUrl("")
                .contact(contact)
                .version("1.0")
                .build();
    }


}
